package practise.alogrithm.gotoSiliconValley.array;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by xinlyu on 8/4/2014.
 */
public class ArrayOverlapCount {
    public int overlapNumber(Pointer[] pointerList){
        Arrays.sort(pointerList);
        int count=0;
        for(int index =1;index<pointerList.length-1;index++){
            if(pointerList[index-1].end>=pointerList[index].start){
                count++;
            }
        }
        if(count>0){
            return count+1;
        }
        return 0;
    }

    public static void main(String[] args){
        System.out.println(new ArrayOverlapCount().overlapNumber(
                new Pointer[]{new Pointer(1,5),new Pointer(10,15),new Pointer(1,10),new Pointer(20,30)
                }));
    }
}
class Pointer implements Comparable<Pointer> {
    Integer start ;
    Integer end;

    Pointer(Integer start, Integer end) {
        this.start = start;
        this.end = end;
    }

    @Override
    public int compareTo(Pointer o) {
        if(o.start!=start){
            return start-o.start;
        }
        else{
            return end-o.end;
        }
    }
}
